package com.superbytecode.cloud.rocketmq.scan;

import com.superbytecode.cloud.common.model.mq.Topic;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.lang.NonNull;

import java.util.Map;

/**
 * All rights Reserved, Designed By www.super-master.com
 *
 * @ProjectName: beacon-cloud
 * @Package: com.superbytecode.cloud.rocketmq
 * @ClassName: MQDefinitionRegistrar
 * @Description: []
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2024/11/1 23:10
 * @Version: V1.0
 * @Copyright: 2024 www.super-master.com Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
public class MQDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata metadata, @NonNull BeanDefinitionRegistry registry) {
        Map<String, Object> annotationAttributes = metadata.getAnnotationAttributes(MQPackageScan.class.getName());
        ClassPathMQDefinitionScanner classPathMQDefinitionScanner = new ClassPathMQDefinitionScanner(registry);
        classPathMQDefinitionScanner.addIncludeFilter(new AnnotationTypeFilter(Topic.class));
        assert annotationAttributes != null;
        classPathMQDefinitionScanner.scan((String[]) annotationAttributes.get("value"));
    }
}